<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        var monkeys=parseInt(prompt("请输入猴子的数量"));
        // alert(monkeys);
        var kicks=3;   //var 为变量提升
        var i=0;
        //创建长度为monkeys的数组
        var monkeyArr=Array(monkeys);
        for(i=0;i<monkeys;i++){
            monkeyArr[i]=i+1;
        }
        i=0;
        while(monkeyArr.length>1){
            i++;
            var t=monkeyArr.shift();
            if(i%kicks!=0){
                monkeyArr.push(t);
            }
        }
        alert(monkeyArr[0]);
    </script>
</body>
</html>